getApp();

var t = require("../../provider/dataApi.js"), o = require("../../provider/pipe.js"), n = require("../../wxParse/article.js");

Page({
    data: {
        uid: "",
        statusBarHeight: "",
        titleBarHeight: "",
        wxshow: !1,
        userinfo: {},
        shareBtn: "",
        isshare: "",
        isloading: !0
    },
    onLoad: function(t) {
        this.setData({
            statusBarHeight: getApp().globalData.statusBarHeight,
            titleBarHeight: getApp().globalData.titleBarHeight
        }), console.log(t), t.parentId && this.btnShare(t.parentId);
    },
    goLogin: function() {
        wx.navigateTo({
            url: "../login/login"
        });
    },
    goVip: function() {
        wx.getStorageSync("uid") ? wx.navigateTo({
            url: "../vip/vip"
        }) : wx.navigateTo({
            url: "../login/login"
        });
    },
    goMyExam: function() {
        wx.getStorageSync("uid") ? wx.navigateTo({
            url: "/pages/myExam/myExam"
        }) : wx.navigateTo({
            url: "../login/login"
        });
    },
    goMedal: function() {
        wx.getStorageSync("uid") ? wx.navigateTo({
            url: "../my-medal/my-medal"
        }) : wx.navigateTo({
            url: "../login/login"
        });
    },
    goInfo: function() {
        wx.getStorageSync("uid") ? wx.navigateTo({
            url: "../my-info/my-info"
        }) : wx.navigateTo({
            url: "../login/login"
        });
    },
    goIntegralmall: function() {
        wx.getStorageSync("uid") ? wx.navigateTo({
            url: "../integral-mall/integral-mall"
        }) : wx.navigateTo({
            url: "../login/login"
        });
    },
    goFeedback: function() {
        wx.getStorageSync("uid") ? wx.navigateTo({
            url: "../feedback/feedback"
        }) : wx.navigateTo({
            url: "../login/login"
        });
    },
    goAbout: function() {
        this.setData({
            wxshow: !0
        });
    },
    confirmwx: function(t) {
        console.log(t.detail);
    },
    onClosewx: function() {
        this.setData({
            close: !1
        });
    },
    gosafeset: function() {
        wx.navigateTo({
            url: "../bindWechat/bindWechat"
        });
    },
    goSignout: function() {
        wx.showModal({
            title: "登出提示",
            content: "点击确定后将清空所有缓存,并退出到登录页,确定登出吗?",
            showCancel: !0,
            confirmText: "确定",
            success: function(t) {
                console.log(t), t.confirm && (wx.clearStorage(), wx.reLaunch({
                    url: "../login/login"
                }));
            }
        });
    },
    bindWechat: function() {
        wx.showModal({
            title: "绑定微信",
            content: "需要绑定微信才能进行下一步操作,点击确定去绑定",
            showCancel: !0,
            confirmText: "确定",
            success: function(t) {
                console.log(t), t.confirm && wx.navigateTo({
                    url: "../bindWechat/bindWechat"
                });
            }
        });
    },
    onShow: function() {
        this.setData({
            uid: wx.getStorageSync("uid")
        }), this.getuserinfo(), this.aboutus();
    },
    btnShare: function(o) {
        t.share({
            uid: o
        }).then(function(t) {
            console.log(t);
        }).catch(function(t) {
            console.log(t);
        });
    },
    onShareAppMessage: function(t) {
        return console.log(t), {
            title: "分享有礼",
            path: "/pages/mine/mine?parentId=" + this.data.uid
        };
    },
    getuserinfo: function() {
        var o = this;
        t.userinfo({
            uid: wx.getStorageSync("uid"),
            op: "getinfo"
        }).then(function(t) {
            console.log(t), wx.setStorageSync("userinfo", t.data.info), wx.setStorageSync("http", t.data.http), 
            o.setData({
                userinfo: t.data.info,
                isloading: !1
            });
        }).catch(function(t) {
            console.log(t), o.setData({
                isloading: !1
            });
        });
    },
    aboutus: function() {
        var a = this;
        t.aboutus({}).then(function(t) {
            console.log(t), null != t.data.about && (t.data.about = o.strcharacterDiscode(t.data.about).replace(/\<img/gi, '<img style="max-width:100px!important;height:auto"'), 
            n.wxParse("article", "html", t.data.about, a, 5));
        }).catch(function(t) {
            console.log(t);
        });
    },
	getUserProfile: function() {
	        wx.getUserProfile({
	            desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
	            success: (res) => {
	                wx.login({
	                  success:(l)=>{
	                    console.log(l),dataApi.login2({
	                        code:l.code,
	                        is_bind:2,
	                        encryptedData:res.encryptedData,
	                        iv:res.iv,
	                        nickName:res.userInfo.nickName,
	                        city:res.userInfo.city,
	                        province:res.userInfo.province,
	                        avatarUrl:res.userInfo.avatarUrl,
	                    }).then(function(tn){
	                        console.log(tn),wx.hideLoading(),wx.showToast({ 
	                            title: tn.message,
	                            icon: "none"
	                        }) ,0 == tn.errno && (wx.setStorageSync("uid", tn.data.uid)  ,setTimeout(function() { 
	                            wx.reLaunch({
	                                url: "/pages/home/home"
	                            });
	                        }, 1500)); 
	                    }).catch(function(tn) {
	                        console.log(tn), wx.hideLoading(), wx.showToast({
	                            title: tn.message,
	                            icon: "none"
	                        });
	                    });
	                  }
	                })
	              
	            }
	          })
	    }
});